import React from 'react';
import { inject, observer } from 'mobx-react';
import { Spin, Checkbox,Modal } from 'antd'
import { WeaRightMenu, WeaLocaleProvider } from 'ecCom';
import { WeaTableNew } from "comsMobx";
import '../../style/export/export.less'
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;


/**
 * 考核设置-考核指标项
 * jiansong 2019/6/18
 */
@inject("exportBlogListStore")
@observer
export default class ExportList extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.exportBlogListStore;
    }

    componentDidMount() {
        const { exportBlogListStore } = this.props;
        exportBlogListStore.doInit();
      }

  

    render() {
        let _this=this;
        const { menu } = _this.props;
        const { loading, tableStore,setIds } = _this.store;
        const rowSelection = {
            onChange(selectedRowKeys, selectedRows) {
             
            },
            onSelect(record, selected, selectedRows) {
                _this.getRowIds(selectedRows,selected);
            },
            onSelectAll(selected, selectedRows, changeRows) {
                _this.getRowIds(selectedRows,selected);
            },
          };
        return (
            <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@4lgekx`} spinning={loading}>
                <div>
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@5vxtva`} datas={menu} showUrlItem={false}>
                        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@y2a51p`}
                            className="quanxian-shezhi"
                            comsWeaTableStore={tableStore}
                            rowSelection={rowSelection}
                            hasOrder
                            needScroll = {true}
                            onOperatesClick={this.onOperatesClick}
                        />
                    </WeaRightMenu>
                </div>
            </Spin>
        )
    }
    getRowIds(selectedRows,selected){
      const { setIds,isShowBatchDel,setContents,setTypes } = this.store;
      let ids = "", content="",type="";
      for (let i = 0; i < selectedRows.length; i++) {
         ids+=selectedRows[i].id+","
         content+=selectedRows[i].content+"_"
         type+=selectedRows[i].type+","
      }
      ids=ids.substring(0,ids.length-1);
      content=content.substring(0,content.length-1);
      type=type.substring(0,type.length-1);
      setIds(ids);
      setContents(content);
      setTypes(type);
      if(selectedRows.length>0){
        isShowBatchDel(true);
      }else{
        isShowBatchDel(false);
      }
    }
    
    showConfirm(record) {
        const { deleteRow } = this.store;
        Modal.confirm({
          title: getLabel(558,'提示') ,
          content: getLabel(83877, '确定要删除吗？'),
          onOk() {
            deleteRow(record)
          },
          onCancel() {}
        });
    }
    //table操作
    onOperatesClick = (record, index, operate, flag) => {
        if (operate.index === '0') {
            record.operation='delete';
            this.showConfirm(record)
           
        }
    }
}